import 'package:flutter/material.dart';
import '../constants/hand_drawn_body_reaction_icon_type.dart';

class HandDrawnBodyReactionIcon extends StatelessWidget {
  final HandDrawnBodyReactionIconType type;
  final double size;
  final Color color;

  const HandDrawnBodyReactionIcon({
    Key? key,
    required this.type,
    this.size = 24,
    this.color = Colors.black,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      size: Size(size, size),
      painter: _HandDrawnBodyReactionIconPainter(
        type: type,
        color: color,
      ),
    );
  }
}

class _HandDrawnBodyReactionIconPainter extends CustomPainter {
  final HandDrawnBodyReactionIconType type;
  final Color color;

  _HandDrawnBodyReactionIconPainter({
    required this.type,
    required this.color,
  });

  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint()
      ..color = color
      ..style = PaintingStyle.stroke
      ..strokeWidth = 2.0
      ..strokeCap = StrokeCap.round;

    final center = Offset(size.width / 2, size.height / 2);
    final radius = size.width / 2 - 4;

    switch (type) {
      case HandDrawnBodyReactionIconType.head:
        _drawHeadIcon(canvas, size, paint);
        break;
      case HandDrawnBodyReactionIconType.sleep:
        _drawSleepIcon(canvas, size, paint);
        break;
      case HandDrawnBodyReactionIconType.digest:
        _drawDigestIcon(canvas, size, paint);
        break;
      case HandDrawnBodyReactionIconType.other:
        _drawOtherIcon(canvas, size, paint);
        break;
    }
  }

  void _drawHeadIcon(Canvas canvas, Size size, Paint paint) {
    // 画头部轮廓
    final path = Path();
    path.moveTo(size.width * 0.3, size.height * 0.3);
    path.quadraticBezierTo(
      size.width * 0.5, size.height * 0.1,
      size.width * 0.7, size.height * 0.3
    );
    path.lineTo(size.width * 0.7, size.height * 0.7);
    path.quadraticBezierTo(
      size.width * 0.5, size.height * 0.9,
      size.width * 0.3, size.height * 0.7
    );
    path.close();
    canvas.drawPath(path, paint);

    // 画眼睛
    canvas.drawCircle(
      Offset(size.width * 0.4, size.height * 0.4),
      size.width * 0.08,
      paint
    );
    canvas.drawCircle(
      Offset(size.width * 0.6, size.height * 0.4),
      size.width * 0.08,
      paint
    );
  }

  void _drawSleepIcon(Canvas canvas, Size size, Paint paint) {
    // 画月亮
    final path = Path();
    path.moveTo(size.width * 0.7, size.height * 0.2);
    path.quadraticBezierTo(
      size.width * 0.8, size.height * 0.5,
      size.width * 0.7, size.height * 0.8
    );
    path.quadraticBezierTo(
      size.width * 0.5, size.height * 0.9,
      size.width * 0.3, size.height * 0.7
    );
    path.quadraticBezierTo(
      size.width * 0.2, size.height * 0.5,
      size.width * 0.3, size.height * 0.3
    );
    path.quadraticBezierTo(
      size.width * 0.5, size.height * 0.1,
      size.width * 0.7, size.height * 0.2
    );
    canvas.drawPath(path, paint);

    // 画星星
    canvas.drawCircle(
      Offset(size.width * 0.2, size.height * 0.3),
      size.width * 0.05,
      paint
    );
    canvas.drawCircle(
      Offset(size.width * 0.8, size.height * 0.7),
      size.width * 0.05,
      paint
    );
  }

  void _drawDigestIcon(Canvas canvas, Size size, Paint paint) {
    // 画胃部轮廓
    final path = Path();
    path.moveTo(size.width * 0.3, size.height * 0.3);
    path.quadraticBezierTo(
      size.width * 0.5, size.height * 0.2,
      size.width * 0.7, size.height * 0.3
    );
    path.lineTo(size.width * 0.7, size.height * 0.7);
    path.quadraticBezierTo(
      size.width * 0.5, size.height * 0.8,
      size.width * 0.3, size.height * 0.7
    );
    path.close();
    canvas.drawPath(path, paint);

    // 画波浪线表示消化
    final wavePath = Path();
    wavePath.moveTo(size.width * 0.4, size.height * 0.5);
    wavePath.quadraticBezierTo(
      size.width * 0.5, size.height * 0.4,
      size.width * 0.6, size.height * 0.5
    );
    wavePath.quadraticBezierTo(
      size.width * 0.7, size.height * 0.6,
      size.width * 0.8, size.height * 0.5
    );
    canvas.drawPath(wavePath, paint);
  }

  void _drawOtherIcon(Canvas canvas, Size size, Paint paint) {
    // 画三个点
    canvas.drawCircle(
      Offset(size.width * 0.2, size.height * 0.5),
      size.width * 0.08,
      paint
    );
    canvas.drawCircle(
      Offset(size.width * 0.5, size.height * 0.5),
      size.width * 0.08,
      paint
    );
    canvas.drawCircle(
      Offset(size.width * 0.8, size.height * 0.5),
      size.width * 0.08,
      paint
    );
  }

  @override
  bool shouldRepaint(_HandDrawnBodyReactionIconPainter oldDelegate) {
    return oldDelegate.type != type || oldDelegate.color != color;
  }
} 